//
//  MainViewController.swift
//  hweibo
//
//  Created by MoChen on 16/3/5.
//  Copyright © 2016年 MoChen. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let mianTabbar = MianTabBar()
        //KVC 给对象提供类似字典的方式 访问对象属性
        //系统的tabbar 是只读属性 不能够直接操作
        print(tabBar.classForCoder)
        setValue(mianTabbar, forKey: "tabBar")
        print(tabBar.classForCoder)
        //添加所有的子视图控制器
        addChildViewController()
    }
    private func addChildViewController() {
        addChildViewController(HomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(HomeViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(HomeViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(HomeViewController(), title: "我", imageName: "tabbar_profile")
    }
    //MARK：添加子视图控制器
    private func addChildViewController(vc: UIViewController, title: String, imageName: String) {
        //设置title
        vc.title = title
        vc.tabBarItem.title = title
        //设置字体
        //vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.redColor()], forState: UIControlState.Selected)
        //设置tintColor
        tabBar.tintColor = UIColor.orangeColor()
        //设置图片
        vc.tabBarItem.image = UIImage(named: imageName)
        
        //设置选中图片
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        let nav = UINavigationController(rootViewController: vc)
        addChildViewController(nav)
    }
}
